<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-btn-group larry-group">
                <button class="layui-btn layui-btn-sm layui-btn-normal"
                        onclick="javascript:layer.open({title:'增加',type:2,area: ['100%', '100%'],content:'<?=url('img/add')?>'});">
                    <i class="layui-icon">&#xe654;</i>
                    <cite>增加</cite>
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger ajaxPost" url="<?=url('img/delall') ?>">
                    <i class="layui-icon">&#xe640;</i>
                    <cite>删除</cite>
                </button>
            </div>
        </div>
        <div class="layui-row layui-form" id="form">
                <div class="layui-col-lg1">
                    <input type="text" id="min_time" name="min_time" placeholder="最小时间" class="layui-input">
                </div>
                <div class="layui-col-lg1">
                    <input type="text" id="max_time" name="max_time" placeholder="最大时间" class="layui-input">
                </div>
                <div class="layui-col-lg1">
                    <select lay-filter="com_quicktime">
                        <option value="0">快捷时间</option>
                        <option value="1">最近1天</option>
                        <option value="2">最近2天</option>
                        <option value="3">最近3天</option>
                        <option value="4">最近4天</option>
                        <option value="5">最近5天</option>
                        <option value="6">最近6天</option>
                        <option value="7">最近7天</option>
                        <option value="8">最近8天</option>
                        <option value="9">最近9天</option>
                        <option value="10">最近10天</option>
                        <option value="20">最近20天</option>
                        <option value="30">最近30天</option>
                        <option value="60">最近60天</option>
                        <option value="90">最近90天</option>
                        <option value="365">最近365天</option>
                    </select>
                </div>
                    <div class="layui-col-lg2">
                        <input type="text" id="" name="keyword" placeholder="请输入标题/标识" class="layui-input">
                    </div>
            <div class="layui-col-lg1">
                <button class="layui-btn layui-btn-normal" onclick="search()">搜索</button>
            </div>
        </div>
        <div class="layui-row">
            <table class="layui-hide" lay-filter="table" id="table"></table>
        </div>
    </div>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="copys">拷贝</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
</script>
<script>
layui.use(['table','form','larry'], function(){
    var form = layui.form;
    var table = layui.table;
    var $ = layui.$;
    var larry = layui.larry;
    form.render('select');
    search = function(){
        var url = "/img/lists";
        var data = $("#form").find("[name]");
        var where = {};
        data.each(function(i,e){
            where[$(e).attr('name')] = $(e).val();
        });
        table.render({
            elem: '#table'
            ,url:url
            ,where:where
            ,method:'post'
            ,cellMinWidth:180
            ,page: true
            ,cols: [[
                {type:'checkbox'},
                {field:'id', title: 'ID',width:80, sort: true,title:'ID'}
                ,{field:'uuid',width:100, title: '图片标识'}
                ,{field:'pic', title: '图片',templet: function(d){
                    return "<img height=30 src='"+d.pic+"' />";
                  }}
                ,{field:'title', title: '标题'}
                ,{field:'width',width:100, title: '图片宽度'}
                ,{field:'height', width:100,title: '图片高度'}
                ,{field:'url', title: '跳转地址'}
                ,{field:'sort', width:100,title: '排序',edit: 'text'}
                ,{field:'create_time',title: '创建时间'}
                ,{field:'action', title: '操作',width:178, align:'center', toolbar: '#barDemo',fixed:"right"}
            ]]
        });
    };
    search();
        search();
        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确认要删除吗?', function (index) {
                    $.ajax({
                        url: "/img/del",
                        method: "post",
                        dataType: "json",
                        data: {id: data.id},
                        success: function (res) {
                            my.action(res);
                            layer.close(index);
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                layer.open({
                    title: '编辑',
                    type: 2,
                    area: ['100%', '100%'],
                    content: '/img/edit?id=' + data.id
                });
            } else if (obj.event === 'copys') {
                $.ajax({
                    url: "/com/copys",
                    method: "post",
                    dataType: "json",
                    data: {table: 'img', id: data.id},
                    success: function (res) {
                        my.action(res);
                    }
                });
            }
        });
});
</script>
